import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import OSS from 'ali-oss';
import { OssController } from './oss.controller';
import { OssService } from './oss.service';

@Module({
  imports: [ConfigModule],
  controllers: [OssController],
  exports: [OssService],
  providers: [
    OssService,
    {
      provide: 'OSS_CLIENT',
      useFactory: async (configService: ConfigService) => {
        return new OSS({
          region: configService.get<string>('oss.region'),
          accessKeyId: configService.get<string>('oss.accessKeyId'),
          accessKeySecret: configService.get<string>('oss.accessKeySecret'),
          bucket: configService.get<string>('oss.bucket'),
        });
      },
      inject: [ConfigService],
    },
  ],
})
export class OssModule {}
